//
//  XQIdentityHeaderView.swift
//  Spark Peso
//
//  Created by 小琦 on 2025/2/6.
//

import UIKit

class XQIdentityHeaderView: UIView {
    
    var onTapHandle: (() -> Void)?
    
    private lazy var titleLb : UILabel = {
        let lb = UILabel()
        lb.textColor = .xq_black
        lb.font = UIFont.systemFont(ofSize: 16, weight: .medium)
        return lb
    }()

    private lazy var arrow : UIImageView = {
        let imageView = UIImageView()
        return imageView
    }()
    
    private lazy var btn : UIButton = {
        let btn = UIButton(type: .custom)
        btn.addTarget(self, action: #selector(btnClick), for: .touchUpInside)
        return btn
    }()
    
    var title : String = "" {
        didSet {
            self.titleLb.text = title
        }
    }
    
    var isSelect : Bool = false {
        didSet {
            self.arrow.image = UIImage(named: isSelect ? "public_accure_top" : "public_accure_bottom")
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.isUserInteractionEnabled = true
        self.backgroundColor = .white
        makeUI()
        makeConstraints()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        makeUI()
        makeConstraints()
    }
    
    private func makeUI() {
        self.addSubview(self.titleLb)
        self.addSubview(self.arrow)
        self.addSubview(self.btn)
    }
    
    private func makeConstraints() {
        self.titleLb.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(17)
        }
        self.arrow.snp.makeConstraints { make in
            make.centerY.equalTo(self.titleLb)
            make.right.equalTo(-33)
            make.width.height.equalTo(13)
        }
        self.btn.snp.makeConstraints { make in
            make.top.right.bottom.equalTo(0)
            make.width.equalTo(100)
        }
    }
    
    @objc private func btnClick() {
        onTapHandle?()
    }
}
